package com.heima.gateway.config;


import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.config.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: XJH
 * @Description: TODO
 * @Date: 2025/10/16 10:38
 * @Version: 1.0
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {

    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("http://localhost:18080")  // 前端地址
                .allowedMethods("GET", "POST", "PUT", "DELETE")
                .allowedHeaders("*")  // 允许所有请求头，或明确包含 X-User-Id
                .exposedHeaders("X-User-Id")  // 允许前端访问的响应头（如果需要）
                .allowCredentials(true);
    }
}